<!--注册 页面-->
<template>

  <div id="register">

    <el-row>
      <el-col :span="20" :offset="12">
        <el-form :model="vipManage" status-icon  label-width="100px" class="demo-ruleForm">


          <el-form-item label="vip卷" prop="voucherId" >
            <el-input placeholder="请输入vip卷" v-model="vipManage.voucherId" ></el-input>
          </el-form-item>


          <el-form-item>
            <el-button type="danger" @click="submitForm('ruleForm')">开通</el-button>
            <el-button type="" @click="resetForm('ruleForm')" >返回</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>

</template>
<script>

  import {ResultStatus} from "../../../constant/ResultStatus";
  import {StringUtil} from "../../../../utils/StringUtil";


  export default {
    data() {

      return {

        vipManage: {
          voucherId: '',
        },

      };
    },
    methods: {
      submitForm: function (formName) {
        this.$axios({
          method: 'post',
          url: 'vip/manage/open',
          data: JSON.stringify(this.vipManage),
          datatype: 'json',
          headers: {
            'content-type': 'application/json;charset=UTF-8'
          },
        }).then((response) => {
          let datas = response.data;
          if (datas.code == ResultStatus.SUCCESS) {
            //修复开通后不能立刻下载的bug
            //将用户信息存入store中
            this.$store.dispatch("setUserInfo", datas.data.userRes);
            //存入cookie
            document.cookie=ResultStatus.SSO_TOKEN_KEY+"="+datas.data.userRes.key;
            this.$notify(StringUtil.success(datas.msg));
            this.$router.push({name: 'vipManage'})
            location.reload();
          } else {
            this.$notify(StringUtil.warning(datas.msg));
            return;
          }

        }).catch(function (error) {
          this.$notify(StringUtil.warning(error.data.msg));
          return false;
        });


      },
      resetForm(formName) {
        this.$router.push({name: 'vipManage'})
      },


    },

  }
</script>

<style>
  #register{
    width: 50%  }
  .el-select .el-input {
    width: 130px;
  }
  .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }
</style>
